<template>
  <div class="lay-out" style="">
    <a-layout>
      <div class="lay-out-head" style="margin-bottom: 60px">
        <a-layout-header style="position: fixed;z-index: 10;">
          <div class="the-biggest-nav" style="min-width: 1550px;overflow-x: hidden;box-shadow: 2px 2px 4px -2px rgba(101,101,101,0.56)">

            <a-menu mode="horizontal" :default-selected-keys="['1']" style="min-width: 1500px;flex-shrink: 0;">
              <a-menu-item key="0" :style="{ padding: 0, marginRight: '38px' }" disabled>

              </a-menu-item>
              <a-menu-item key="1" @click="goTo('/')" style="margin-left: 13%;"><p class="HomeView-p">首页</p></a-menu-item>
              <a-menu-item key="2"><p class="HomeView-p" @click="goTo('/Ssearch')">校招</p></a-menu-item>
              <a-menu-item key="3"><p class="HomeView-p" @click="goTo('/practiceSearch')">实习</p></a-menu-item>
              <a-menu-item key="4"><p class="HomeView-p" @click="goTo('/')">校园圈</p></a-menu-item>
              <a-menu-item key="5" style="margin-right: 25%;" @click="goTo('/Csearch')"><p class="HomeView-p">公司</p></a-menu-item>
              <!--            <a-menu-item key="7">待定</a-menu-item>-->
              <!--            <a-menu-item key="8">待定</a-menu-item>-->
              <!--            如果未登录-->
              <a-menu-item key="14" v-if="user!=null" @click="goTo('/chat')"><p class="HomeView-p">聊天</p></a-menu-item>
              <a-menu-item key="11" v-if="user==null" @click="goTo('/login')"><p class="HomeView-p">登录/注册</p></a-menu-item>
              <!--            如果登录了-->
              <a-menu-item key="12" v-if="user!=null" @click="goTo('/jobPosting')"><p class="HomeView-p">发布招聘</p></a-menu-item>

              <a-menu-item key="13" v-if="user!=null&&user.identityId=='20'" @click="goTo('/HrCenter')">
                <p class="HomeView-p" style="margin-right: 10px;">{{user.username}}</p>
                <a-avatar :style="{ backgroundColor: '#abc0f3', margin: 0 }" :size="32">
                  <img v-if="user.userImg!=null"
                       alt="avatar"
                       :src="BASE_URL+user.userImg"
                  />
                  <img v-else
                       src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"
                  />
                </a-avatar>
              </a-menu-item>
              <a-menu-item key="14" v-if="user!=null" @click="logout"><p class="HomeView-p">退出</p></a-menu-item>
            </a-menu>
          </div>
          <img src="logo.png" style="width: 55px;position: fixed;
          top: 10px;
            left: 11%;">
        </a-layout-header>
      </div>

      <a-layout-content>
<!--        <button @click="cg">点我切换</button>-->
<!--        主体里边是可变内容-->
        <router-view/>
      </a-layout-content>
    </a-layout>
  </div>

</template>

<script setup>
import { useRouter } from 'vue-router';
import {onMounted, ref} from "vue";
import axios from "axios";
import {ElMessage} from "element-plus";

const router = useRouter();
const user = ref(getUser());
const searchUserForm = ref();

const goTo = (path) => {
  router.push(path);
};

onMounted(()=>{
  if(user.value != null){
    loadUser();
  }else{

  }
});

const loadUser = () => {
  let id = user.value.userId;
  console.log("1111111111id="+id);
  //根据userId查询头像
  axios.get(BASE_URL+'/v1/user/selectByUserId/'+id)
      .then((response) => {
        if (response.data.code === 2000) {
          searchUserForm.value = response.data.data;
          console.log(searchUserForm.value.userImg);
          user.value.userImg = searchUserForm.value.userImg;
          console.log("12321123"+user.value.userImg);
        } else {
          ElMessage.error(response.data.msg);
        }
      })
}

const logout = ()=>{
  if (confirm('您确认要退出吗?')){
    //清空localStorage中保存的数据,但注意这并不会影响已经取出来的user数据
    localStorage.clear();
    //还需要将已取出来的响应式变量user的数据重置为null,这样页面才会立即跟着重置
    user.value = null;
    router.push('/');
  }
}
</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
}
.foot-div{
  max-width: 1150px;
  text-align: center;
  margin: 20px auto;
}

.HomeView-p {
  display: inline-block;
}
footer{
  width: 100%;
  height:300px;
  background-color: #3b3b3b;
}
</style>
